//
//  CartoonShowViewController.m
//  WuLi
//
//  Created by Gollum on 16/9/25.
//  Copyright © 2016年 Gollum. All rights reserved.
//

#import "CartoonShowViewController.h"
#import "SDCycleScrollView.h"
#import "NetworkTool.h"
#import "UIImageView+WebCache.h"
#import "CartoonShowImageModel.h"
#import "CartoonShowImageData.h"
#import "CartoonContentCell.h"


#define kCartoonContentCellReuse @"CartoonContentCellReuse"
@interface CartoonShowViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,assign)BOOL isHiddenStatusBar ;
@property (nonatomic,strong)CartoonShowImageModel *cartoonShow;
@property (nonatomic,strong)NSMutableArray *dataArray;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic,strong)UISlider *progress;

@end

@implementation CartoonShowViewController
//设置状态栏隐藏
- (BOOL)prefersStatusBarHidden

{
    return YES;
    
//    if (_isHiddenStatusBar) {
//        
//        return YES;
//        
//    }
//    
//    return NO;
    
}

- (void)viewWillAppear:(BOOL)animated{
//    [self prefersStatusBarHidden];

    [self setNeedsStatusBarAppearanceUpdate];

}


- (void)viewDidLoad {
    [super viewDidLoad];
   _dataArray = [NSMutableArray array];
    [self hanldeData];
    // Do any additional setup after loading the view from its nib.
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 44)];
    [self.view addSubview:view];
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame = CGRectMake(8, 8, 28,28 );
    [backButton setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(handleBack:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:backButton];
    NSLog(@"-=-=-=-=%@",_cidString);
    [_tableView registerClass:[CartoonContentCell class] forCellReuseIdentifier:kCartoonContentCellReuse];
}

- (void)hanldeData{
    NSString *str1 = @"http://dajiaochong.517w.com/dacu_app/get_chapter.php?cid=";
    
    
    //    NSString *urlString = @"http://dajiaochong.517w.com/dacu_app/app/?c=BookDetail&a=get_chapter_list&view_type=1&id=2335&ui=0&ui_id=0&userid=0&view_type=1";
    
    NSString *urlString = [str1 stringByAppendingString:_cidString] ;
    
    
    NSDictionary *header = @{@"User-Agent":@"kidstone.cn/2.3.0/10/iPad/iOS 9.3.2/iPad/AC4A678F-C131-43C6-9024-873D3BD1A130/kidstone"};
    [NetworkTool GET:urlString andBody:nil andHeader:header andResponse:JHJSON andSuccessBlock:^(id result) {
        
        NSLog(@"=-=-=-%@",result);
        _cartoonShow = [CartoonShowImageModel modelWithDic:result];
        
        [_dataArray addObject:_cartoonShow];
        [_tableView reloadData];
       
    } andFailureBlock:^(NSError *error) {
        
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _cartoonShow.data.count;

}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    CartoonContentCell *cell = [tableView dequeueReusableCellWithIdentifier:kCartoonContentCellReuse];
    NSString *str1 = @"http://cdn.517w.com//";
    NSString *urlString = [str1 stringByAppendingString:_cartoonShow.data[indexPath.row].image];
    NSURL *url = [NSURL URLWithString:urlString];
    [cell.content sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"default_image"]];
    
    return cell;

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return [_cartoonShow.data[indexPath.row].height floatValue] / 2;

}


- (void)handleBack:(UIButton *)button{

    [self dismissViewControllerAnimated:YES completion:^{
        
    }];


}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
